import { Body, Controller, Get, Post, Query, UseGuards } from "@nestjs/common";
import { ApiOperation, ApiTags } from "@nestjs/swagger";
import { Roles } from "/@/logical/adminModule/auth/roles.decorator";
import { AuthEnum } from "/@/enum/auth.enum";
import { RolesGuard } from "/@/logical/adminModule/auth/roles.guard";
import { OrderService } from "../service/order.service";
import {
  DeliverGoodsDto,
  GetOrderDto,
  ReceivedGoodsDto,
} from "../dto/order.dto";
import { GetOrderByIdDto } from "/@/logical/weappModule/dto/order.dto";

@ApiTags("Order")
@Controller("order")
@UseGuards(RolesGuard)
export class OrderController {
  constructor(private readonly orderService: OrderService) {
    //
  }

  // 获取订单 根据id
  @Get("getOrderById")
  @ApiOperation({ summary: "获取订单 根据id" })
  async getOrderById(@Query() query: GetOrderByIdDto): Promise<any> {
    return this.orderService.getOrderById(query);
  }

  // 获取该订单id下的购物列表
  @Get("getOrderCartById")
  @ApiOperation({ summary: "获取订单 根据id" })
  async getOrderCartById(@Query() query: GetOrderByIdDto): Promise<any> {
    return this.orderService.getOrderCartById(query);
  }

  @Get("getOrderList")
  @Roles(AuthEnum.OPERATE, AuthEnum.OPERATE_VIEW)
  @ApiOperation({ summary: "获取订单列表" })
  async getOrderList(@Query() query: GetOrderDto): Promise<any> {
    return this.orderService.getOrderList(query);
  }

  // deliver goods 发货
  @Post("deliverGoods")
  @Roles(AuthEnum.OPERATE)
  @ApiOperation({ summary: "标记发货" })
  async deliverGoods(@Body() params: DeliverGoodsDto): Promise<any> {
    return this.orderService.deliverGoods(params);
  }

  // 标记订单完成，确认用户收货了
  @Post("receivedGoods")
  @Roles(AuthEnum.OPERATE)
  @ApiOperation({ summary: "标记收货" })
  async receivedGoods(@Body() params: ReceivedGoodsDto): Promise<any> {
    return this.orderService.receivedGoods(params);
  }
}
